package top.dszy.test.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class JDBC {

    private static final String URL = "jdbc:mysql://localhost:3306/dszy?useUnicode=true&characterEncoding=utf8";
    private static final String USERNAME = "root";
    private static final String PASSWORD = "root";

    public static void main(String[] args) throws Exception{
        Class.forName("com.mysql.jdbc.Driver");
        Connection conn = DriverManager.getConnection(URL, USERNAME, PASSWORD);

        PreparedStatement pstmt = conn.prepareStatement("select * from city");

        ResultSet rs = pstmt.executeQuery();
        int col = rs.getMetaData().getColumnCount();
        while (rs.next()){
            for (int i = 1; i <= col; i++) {
                System.out.print(rs.getString(i) + "\t");
                if((i == 2) && (rs.getString(i).length() < 8)){
                    System.out.println("\t");
                }
                System.out.println();
            }
        }



    }

    private static void insert() throws Exception{

    }
}
